package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.Content;
import com.zr.model.Type;
import com.zr.service.ContentService;
import com.zr.service.impl.ContentServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class GetMaxNumerContentAction extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf-8");
		ContentService cs = new ContentServiceImpl();
		ArrayList<Type> list = cs.getMaxNumberContent();
		StringBuffer msg = new StringBuffer();
		JSONArray json = new JSONArray();
		for (Type content : list) {
			/*msg.append(content.getCid()+"-"+content.getCtitle()+" ");*/
			JSONObject obj = new JSONObject();
			obj.put("id", content.getTname());
			obj.put("text", content.getTname());
			json.add(obj);
		}
 		/*HttpSession session = req.getSession();		
		session.setAttribute("maxContent", msg.toString());
		session.setAttribute("maxContent2", list);*/
		PrintWriter pw = resp.getWriter();
		pw.write(json.toString());
	}
}
